package cntr.proxies;


import cntr.JGbContainer;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by Thanh-Trung Pham.
 */
public class RequiredRoleProxy implements InvocationHandler {
    private String m_strProvidedComponentInstanceName; //the name of the component instance playing the provided role.
    private String m_strProvidedContainerName; //the name of the container hosting the component instance playing the provided role.
    private JGbContainer m_oJGbContainer;

    /**
     * The constructor.
     *
     * @param requiredContainer             the container of the component instance playing the required role (a.k.a the local container).
     * @param providedContainerName         the name of the container hosting the component instance playing the provided role.
     * @param providedComponentInstanceName the name of the container hosting the component instance playing the provided role.
     */
    public RequiredRoleProxy(JGbContainer requiredContainer, String providedContainerName, String providedComponentInstanceName) {
        m_oJGbContainer = requiredContainer;
        m_strProvidedContainerName = providedContainerName;
        m_strProvidedComponentInstanceName = providedComponentInstanceName;


    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return m_oJGbContainer.invokeRPCMethod(m_strProvidedContainerName, m_strProvidedComponentInstanceName, method, args);
    }


}
